<?php
/**
 * Created by PhpStorm.
 * User: ytlmi
 * Date: 2018/4/18
 * Time: 9:44
 */

namespace app\snpdetection\model;

use app\common\model\BaseModel;

class Disease extends BaseModel
{
    /**
     * @param array $value
     * @throws \Exception
     * @return string
     */
    public function setDiseaseMarkerAttr($value)
    {
        if (is_array($value)){
            return serialize($value);
        }else{
            throw new \Exception('错误的位点设置');
        }
    }
    public function getDiseaseMarkerAttr($value)
    {
        return $this->unserialize($value);
    }


    /**
     * @param array $data
     * @param array $value
     * @throws \Exception
     * @return string
     * 风险判定规则
     */
    public function setRiskRoleAttr($value,$data)
    {
        $diseaseName=$data['disease_name'];
        $controller=new \app\snpdetection\controller\Disease();
        $markerCount=count($data['disease_marker']);
        if ($markerCount===0) throw new \Exception('未设置疾病包含的基因位点');
        if (count($value)!==pow(3,$markerCount)) throw new \Exception('风险判定规则数量错误');
        foreach ($value as $item) {
            if (!(isset($item['risk']) && is_numeric($item['risk']))) throw new \Exception('风险数值设置错误');
        }
        return serialize($value);
    }

    public function getRiskRoleAttr($value)
    {
        return $this->unserialize($value);
    }

    /**
     * @param array $value
     * @throws \Exception
     * @return string
     */
    public function setLevelRoleAttr($value)
    {
        if (is_array($value)){
            foreach ($value as $point=>$level){
                if (!is_numeric($point)) throw new \Exception('错误的风险分割点:'.$point);
                if (!is_numeric($level)) throw new \Exception('错误的风险等级:'.$level);
            }
            return serialize($value);
        }else{
            throw new \Exception('错误的风险分级设置');
        }
    }
    public function getLevelRoleAttr($value)
    {
        return $this->unserialize($value);
    }

    /**
     * @param array $value
     * @throws \Exception
     * @return string
     */
    public function setResultRoleAttr($value)
    {
        if (is_array($value)){
            foreach ($value as $point=>$level){
                if (!is_numeric($point)) throw new \Exception('错误的风险分割点:'.$point);
            }
            return serialize($value);
        }else{
            throw new \Exception('错误的结果分级设置');
        }
    }
    public function getResultRoleAttr($value)
    {
        return $this->unserialize($value);
    }


}